package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface UserMapper extends BaseMapper<User> {
    @Select("select username,id,PASSWORD from t_user where USERNAME =#{username}")
    UserVO findUserByUsername(@Param("username") String username);

    @Select("select tr.KEYWORD,tr.ID " +
            "from t_user_role tur,t_role tr " +
            "where tur.ROLE_ID = tr.ID " +
            "and tur.USER_ID =#{id}")
    List<RoleVO> findRolesByUserId(@Param("id") Integer id);

    @Select("select tp.KEYWORD " +
            "from t_role_permission trp,t_permission tp " +
            "where trp.PERMISSION_ID = tp.id " +
            "and trp.ROLE_ID = #{id}")
    List<Permission> findPermissionByRid(Integer id);
}
